SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[paExisteCUISEReparticionUsuario]

@CUISE INT,
@Reparticion INT, 
@Existe  BIT OUTPUT 


AS

SET NOCOUNT ON
SET DATEFORMAT dmy

DECLARE @RegistrosEncontrados INT 
DECLARE @IdOrganizacion INT

SELECT @IdOrganizacion = idOrganizaciones FROM tb_Organizaciones WHERE CUISE = @CUISE

SELECT @RegistrosEncontrados =  COUNT(*) FROM tb_OrganizacionesPorReparticion
	 WHERE IdReparticion = @Reparticion AND IdOrganizacion = @IdOrganizacion


SET @Existe = 0 
IF @RegistrosEncontrados  > 0
    SET @Existe = 1

RETURN @Existe
GO
GRANT EXECUTE ON  [dbo].[paExisteCUISEReparticionUsuario] TO [GestionInstitucional]
GRANT EXECUTE ON  [dbo].[paExisteCUISEReparticionUsuario] TO [PersonalDocente]
GRANT EXECUTE ON  [dbo].[paExisteCUISEReparticionUsuario] TO [PersonalDocenteDireccion]
GRANT EXECUTE ON  [dbo].[paExisteCUISEReparticionUsuario] TO [SoloVer]
GO
